"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const components_1 = require("@tarojs/components");
const form_taro3_react_1 = require("form-taro3-react");
// import { copyrightTypeCHN } from "../../../util/copyright-type";
require("./copyright-submit.scss");
const taro_1 = require("@tarojs/taro");
class CopyrightSubmit extends react_1.Component {
    constructor() {
        super(...arguments);
        // 表单 Ref
        this.formRef = react_1.createRef();
        this.state = {
            workType: [
                "文学作品",
                "口述作品",
                "音乐作品",
                "戏剧作品",
                "舞蹈作品",
                "杂技作品",
                "美术作品",
                "摄影作品",
                "工程设计图",
                "产品设计图",
                "地图",
                "示意图",
                "模型作品",
                "建筑作品",
                "拍摄独创作品",
                "电影作品",
                "汇编作品"
            ],
            creativeNature: ["原创", "改编", "翻译", "汇编", "注释", "整理", "其他"],
            rightAcquisitionMode: ["原始", "继承", "承受", "其他"],
            attributionOfWorks: [
                "个人作品",
                "合作作品",
                "法人作品",
                "职务作品",
                "委托作品"
            ],
            formData: {},
            workTypeValue: "",
            creativeNatureValue: "",
            rightAcquisitionModeValue: "",
            attributionOfWorksValue: ""
        };
        this.handleChange = res => {
            console.log(this.state.workType[res]);
            this.setState({
                workTypeValue: this.state.workType[res]
            });
        };
        this.handleChange1 = res => {
            this.setState({
                creativeNatureValue: this.state.creativeNature[res]
            });
        };
        this.handleChange2 = res => {
            this.setState({
                rightAcquisitionModeValue: this.state.rightAcquisitionMode[res]
            });
        };
        this.handleChange3 = res => {
            this.setState({
                attributionOfWorksValue: this.state.attributionOfWorks[res]
            });
        };
    }
    /**
     * 表单校验
     */
    validate() {
        var _a;
        // const {attributionOfWorks,rightAcquisitionMode,creativeNature,workType} = this.state
        (_a = this.formRef.current) === null || _a === void 0 ? void 0 : _a.validate().then(() => {
            var _a, _b;
            // 校验通过
            // 获取表单值
            console.log((_a = this.formRef.current) === null || _a === void 0 ? void 0 : _a.getFieldsValue());
            const { workName, content, ownershipOfRights } = (_b = this.formRef.current) === null || _b === void 0 ? void 0 : _b.getFieldsValue();
            const data = {
                userCopyRightType: '1',
                workName,
                content,
                ownershipOfRights,
                workType: this.state.workTypeValue,
                creativeNature: this.state.creativeNatureValue,
                rightAcquisitionMode: this.state.rightAcquisitionModeValue,
                attributionOfWorks: this.state.attributionOfWorksValue
            };
            this.setState({
                formData: data
            });
            taro_1.default.showLoading({ title: "上传中,请稍后" });
            taro_1.default.cloud
                .callFunction({
                name: "logins",
                data: {
                    $url: "addCopyRight",
                    data: this.state.formData
                }
            })
                .then(res => {
                console.log(res);
                if (res.result.code === 0) {
                    taro_1.default.showToast({ title: "提交成功", icon: "success" }).then(() => {
                        taro_1.default.navigateTo({
                            url: '/pages/index/index'
                        });
                    });
                }
            });
        }).catch(error => {
            // 校验不通过
            console.log(error);
        });
    }
    render() {
        return (<components_1.View className="index">
        <form_taro3_react_1.CustomizeForm ref={this.formRef} 
        //   defaultValue={{ content: "请输入作品创作说明" }}
        onValueChange={diff => {
            console.log(diff);
        }}>
          <form_taro3_react_1.FormTextInput label="作品名称" fieldProps={{
            name: "workName",
            placeholder: "请输入作品名称"
        }} rules={{ required: true, message: "作品名称不能为空" }}/>
          <form_taro3_react_1.FormPicker label="作品类型" onPickerChange={this.handleChange.bind(this)} fieldProps={{
            name: "workType",
            mode: "selector",
            range: this.state.workType
        }} rules={{ required: true, message: "作品类型不能为空" }}/>
          <form_taro3_react_1.FormPicker label="作品创作性质" onPickerChange={this.handleChange1.bind(this)} fieldProps={{
            name: "creativeNature",
            mode: "selector",
            range: this.state.creativeNature
        }} rules={{ required: true, message: "作品创作性质不能为空" }}/>
          <form_taro3_react_1.FormPicker label="权利取得方式" onPickerChange={this.handleChange2.bind(this)} fieldProps={{
            name: "rightAcquisitionMode",
            mode: "selector",
            range: this.state.rightAcquisitionMode
        }} rules={{ required: true, message: "权利取得方式不能为空" }}/>
          <form_taro3_react_1.FormPicker label="作品归属" onPickerChange={this.handleChange3.bind(this)} fieldProps={{
            name: "attributionOfWorks",
            mode: "selector",
            range: this.state.attributionOfWorks
        }} rules={{ required: true, message: "作品归属不能为空" }}/>
          
          <form_taro3_react_1.FormTextArea label="作品创作说明" fieldProps={{ name: "content", placeholder: "请输入作品创作说明" }} rules={{ required: true, message: "作品创作说明不能为空" }}/>
          
          
          <form_taro3_react_1.FormCheckboxGroup label="权利拥有方式" fieldProps={{
            name: "ownershipOfRights"
        }} options={[
            { label: "发表权", value: "FB" },
            { label: "署名权", value: "SM" },
            { label: "修改权", value: "XG" },
            { label: "保护作品完整权", value: "BHZPWZ" },
            { label: "复制权", value: "FZ" },
            { label: "发行权", value: "FX" },
            { label: "出租权", value: "CZ" },
            { label: "展览权", value: "ZL" },
            { label: "表演权", value: "BY" },
            { label: "放映权", value: "FYIN" },
            { label: "广播权", value: "GB" },
            { label: "信息网络传播权", value: "XXWLCB" },
            { label: "摄影权", value: "SY" },
            { label: "改编权", value: "GB" },
            { label: "翻译权", value: "FYI" },
            { label: "汇编权", value: "HB" },
            { label: "其他", value: "QT" }
        ]} rules={{ required: true, message: "权利拥有方式不能为空" }}/>
          <components_1.Button className='btn' onClick={this.validate.bind(this)}>提交申请</components_1.Button>
        </form_taro3_react_1.CustomizeForm>
      </components_1.View>);
    }
}
exports.default = CopyrightSubmit;
//# sourceMappingURL=copyright-submit.jsx.map